/**
 * 验证辅助
 * @author shenyc
 *
 ******************************************************************************/

/**
 * 扁平菜单列表
 * @param menuList
 * @returns
 */
export function getFlatMenuList(menuList: MenuOptions[]): MenuOptions[] {
    let newMenuList: MenuOptions[] = JSON.parse(JSON.stringify(menuList));
    return newMenuList.flatMap((item) => [item, ...(item.children ? getFlatMenuList(item.children) : [])]);
}

/** 显示菜单列表 */
export function getShowMenuList(menuList: MenuOptions[]) {
    let newMenuList: MenuOptions[] = JSON.parse(JSON.stringify(menuList));
    return newMenuList.filter((item) => {
        item.children?.length && (item.children = getShowMenuList(item.children));
        return !item.meta?.isHide;
    });
}

/** 取得面包屑 */
export const getAllBreadcrumbList = (menuList: MenuOptions[], parent = [], result: { [key: string]: any } = {}) => {
    for (let item of menuList) {
        result[item.path] = [...parent, item];
        if (item.children) getAllBreadcrumbList(item.children, result[item.path], result);
    }
    return result;
};
